<?php
include_once( "JO_01_configuration.php"	);
include_once( "JO_02_function.php"		);
$key=$_GET['tel'];
$sea=addslashes($_GET['art']);

$JO_MySQL = new mysqli( $JO_DB_host, $JO_DB_user, $JO_DB_password, $JO_DB_database );
$JO_MySQL -> query( "SET NAMES 'UTF8'" );
					if($sea=="")
				{
			 		$total=50;
					$page=1;
					$limit=10;
					if(($total%$limit)!=0) {$numpages=(int)($total/$limit)+1;}
            		else                {$numpages=$total/$limit;}
            		if(isset ($_REQUEST["Page"])){$page=$_REQUEST["Page"];}
					$vt=(($page-1)*$limit);
            		$query="SELECT
artist.`name`,
rbt.rbtcode,
rbt.note,
rbt.telco
FROM
artist
INNER JOIN music ON artist.`key` = music.artist
INNER JOIN rbt ON music.`key` = rbt.music
WHERE
rbt.telco = '$key'
ORDER BY
rbt.note ASC limit $vt ,$limit";
					}
					else
					{
						$query="SELECT artist.name, rbt.rbtcode, rbt.note, rbt.telco
								FROM artist
								INNER JOIN music ON artist.key = music.artist
								INNER JOIN rbt ON music.key = rbt.music
								WHERE (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(artist.name,'đ','d'),'(',''),')',''),'\'',''),'&',''),'-',''),' ',''),'_',''),'!',''),'.',''),'>',''),'<','')	
							LIKE  '%$sea%'
								
								OR REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(rbt.note,'đ','d'),'(',''),')',''),'\'',''),'&',''),'-',''),' ',''),'_',''),'!',''),'.',''),'>',''),'<','')	
							LIKE '%$sea%')
								AND rbt.telco = '$key'
							;";
							
					$recordSet = JO_query( $query );
					$total=$recordSet->num_rows;
					if($total>=1)
					{
					$page=1;
					$limit=10;
					if(($total%$limit)!=0) {$numpages=(int)($total/$limit)+1;}
            		else                {$numpages=$total/$limit;}
            		if(isset ($_REQUEST["Page"])){$page=$_REQUEST["Page"];}
					$vt=(($page-1)*$limit);
            		$query="SELECT artist.name, rbt.rbtcode, rbt.note, rbt.telco
								FROM artist
								INNER JOIN music ON artist.key = music.artist
								INNER JOIN rbt ON music.key = rbt.music
								WHERE (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(artist.name,'đ','d'),'(',''),')',''),'\'',''),'&',''),'-',''),' ',''),'_',''),'!',''),'.',''),'>',''),'<','')	
							LIKE  '%$sea%'
								
								OR REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(rbt.note,'đ','d'),'(',''),')',''),'\'',''),'&',''),'-',''),' ',''),'_',''),'!',''),'.',''),'>',''),'<','')	
							LIKE '%$sea%')
								AND rbt.telco = '$key'
					limit $vt ,$limit";	
					}
					else
					{
					if($key=='VTL8x88')
			echo '<div style="text-align:center;width:100%;font-weight:bold">Tổng Đài Viettel ko có nhạc chờ của ca sĩ này</div>';
		
		if($key=='VMS8x88')
			echo '<div style="text-align:center;width:100%;font-weight:bold">Tổng Đài Mobiphone ko có nhạc chờ của ca sĩ này</div>';
	
		if($key=='GPC8x88')
			echo '<div style="text-align:center;width:100%;font-weight:bold">Tổng Đài VinaPhone ko có nhạc chờ của ca sĩ này</div>';
	
		if($key=='VNM8x88')
			echo '<div style="text-align:center;width:100%;font-weight:bold">Tổng Đài Vietnammobile ko có nhạc chờ của ca sĩ này</div>';
		
		if($key=='SFN8x88')
			echo '<div style="text-align:center;width:100%;font-weight:bold">Tổng Đài Sfone ko có nhạc chờ của ca sĩ này</div>';
	
		if($key=='BEE8x88')
			echo '<div style="text-align:center;width:100%;font-weight:bold">Tổng Đài Beeline ko có nhạc chờ của ca sĩ này</div>';	
					}
					}
					$recordSet = JO_query( $query );
					if( $recordSet -> num_rows ) while( $records = $recordSet -> fetch_array( ) ) {
					?>
<?php 

echo '<div style="width:15px;float:left;margin-right:30px;margin-top:4px;margin-bottom:4px"><img src="JO_80_image/my_music.png" width="30px;"/></div>';
echo '<div style="width:240px;float:left;margin-top:4px;margin-bottom:4px;">'.$records["note"].'</br>Artist : '.$records["name"].'</div>';
echo '<div style="margin-top:4px !important ;width:100px;float:left;">'.$records['rbtcode'].'</div>';
 			$ct="";
            $arrrbt=array();
            $arrrbt=split("<br>", $records['rbtcode']);
            foreach ($arrrbt as $value){
			if($value!=""){
		echo "<div style=\"margin-top:4px !important ;width:30px ;float:left;cursor:pointer\" onClick=\"showobj('JO_63_ajax_wmplayer.php?id=".trim($value," ")."&tel=".$key."','rbtplayer');\"><img src='JO_80_image/JO_31_icon_stream_on.png'width='15px' /></div>";
			}
			}
echo '<div class="cleared"></div>';
?>
<?php } ?>
<?php
echo "<div style='text-align:center;width:100%;font-weight:bold'>";

 					if($numpages>1){
                    if($page>2){
                    ?>


<div style="cursor:pointer;width:20px;float:left;margin-top:4px" onclick="tuyen_du_lieu('<?=$key ?>','1',<?=$sea?>);">◀</div>
<?
                    }
                    if($page>1){
                    ?>
<div style="cursor:pointer;width:20px;float:left;margin-top:4px" onclick="tuyen_du_lieu('<?=$key ?>','<?=($page-1)?>',<?=$sea?>);">◁</div>
<?
                    }
                    if($page-4>1) echo "<div style='cursor:pointer;width:15px;float:left;margin-top:4px'>...</div>";
                    ###########################################
					for($i=$page-4;$i<=($page-1);$i++){
                        if($i>0){
                        ?>
<div style="cursor:pointer;width:20px;float:left;margin-top:4px" onclick="tuyen_du_lieu('<?=$key ?>','<?=$i?>','<?=$sea?>');">
  <?=$i?>
</div><!--indanh sach típ theo--->
<?
                        }
                    }
					
                    echo  "<div style='cursor:pointer;width:20px;float:left;margin-top:4px'><u>".$page."</u></div>";# in danh sach hiện tại
					for($i=$page+1;$i<=($page+4);$i++){
                        if($i<=$numpages){
					    ?>
<div style="cursor:pointer;width:20px;float:left;margin-top:4px" onclick="tuyen_du_lieu('<?=$key?>','<?=$i?>','<?=$sea?>');">
  <?=$i?>
</div>
<?
						
                        }
                    }
					############################################
                    if($page+4<$numpages) echo "<div style='cursor:pointer;width:15px;float:left;margin-top:4px'>...</div>";
                    if($page<$numpages){
                    ?>
<div style="cursor:pointer;width:20px;float:left;margin-top:4px" onclick="tuyen_du_lieu('<?=$key?>',<?=($page+1)?>,'<?=$sea?>');">▷</div>
<?
                    }
                    if($page<($numpages-1)){
                    ?>
<div style="cursor:pointer;width:20px;float:left;margin-top:4px" onclick="tuyen_du_lieu('<?=$key ?>','<?=$numpages ?>','<?=$sea?>');">▶</div>
<?
                    }

                }
			echo "</div>";
					
	

		
		?>